home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue26 / chessbrd / CHESSBRD.ZIP / CPP / CHESSBRD.TXT < prev    next >
Encoding:
Text File  |  1997-09-08  |  16.0 KB  |  416 lines

  1. ---------------------------------------------------------------------------
  2. Welcome to the Chessboard component for Borland C++ Builder !
  3.  
  4. version 2.0 - September 7th 1997
  5. ---------------------------------------------------------------------------
  6. What's New:
  7.  
  8. Now drop a ChessComponent on a form and you have a complete
  9. multithreaded Chess application.
  10.  
  11. The Chessboard Comonent has been linked to the engine of
  12. Tom's Simple Chess Program, a complete chess program that is very
  13. interesting if you take in consideration that the source is very little.
  14.  
  15. -New Properties:
  16.  
  17. bool Thinking (read-only)
  18. Is set to TRUE if the computer is thinking about a move.
  19.  
  20. TThreadPriority ThinkingPriority
  21. Sets the priority of the thinking thread. Cannot be higher than tpNormal.
  22.  
  23. int SearchDepth
  24. Sets the searchdepth of the chess engine. With each value the searchdepth
  25. is increased, the time it takes to calculate a move grows exponentially.
  26.  
  27. bool ComputerPlaysBlack
  28. Lets the computer think and move automatically when it's black's turn.
  29.  
  30. bool ComputerPlaysWhite
  31. Lets the computer think and move automatically when it's white's turn.
  32.  
  33. -New Methods:
  34.  
  35. void __fastcall CancelThinking(void)
  36. Stops calculating if the computer was thinking about a move.
  37.  
  38. void __fastcall MoveNow (void)
  39. Starts calculating. The thinkingthread is being set to a state in which
  40. it produces moves. Function returns before calculation has completed.
  41.  
  42. -New Events:
  43.  
  44. OnThreefoldPosition
  45. Occurs when the board enters into a position for the third time in
  46. a game.
  47.  
  48. ---------------------------------------------------------------------------
  49.  
  50. Description:
  51.  
  52. The Chessboard component provides a component for a complete
  53. multithreaded chess application. The chess engine comes from
  54. Tom's Simple Chess Program. It features a customizable 2D
  55. Chessboard that can keep track of a game and verify the legality
  56. of moves.
  57.  
  58. It allows the programmer to trap  the following events:
  59.  
  60. LegalMove, Illegal Move, Capture, En Passant, Castling, Promotion,
  61. Check, Mate, Stale Mate, Threefold position and Only Two Kings Left.
  62.  
  63. The colors, size, Pieces and Squares can be customized. The component
  64. can be resized at runtime.
  65.  
  66. The Chessboard component for Borland C++ Builder
  67. comes with the following files:
  68.  
  69. ChessBrd.cpp (source file), ChessBrd.h (header file),
  70. ChessBrd.dcr (resource file),ChessBrd.txt (current file),
  71. ChThread.Cpp (second source file) and ChThread.h (second header file).
  72. ---------------------------------------------------------------------------
  73. Installation of the component:
  74.  
  75. Start Borland C++ Builder.
  76. Select "Component", "Install" ,"Add" and
  77. "Browse" and then browse to the file CHESSBRD.CPP. The component will
  78. appear on a tab called Chess.
  79. ---------------------------------------------------------------------------
  80. Product History:
  81.  
  82. version 2.0  - September 1997
  83.       * Linked the CPP version of the component to Tom's Simple Chess Program.
  84.       * Added properties Thinking, ThinkingPriority, SearchDepth,
  85.         ComputerPlaysBlack, ComputerPlaysWhite
  86.       * Added methods MoveNow, CancelThinking
  87.       * Added event OnThreefoldPosition
  88.       * Got rid of the warning 'Duplicate Resources' for the
  89.         PAS resource has now been separated from the CPP resource.
  90. version 1.11 - July 25th 1997
  91.       * Small bug in PAS file did not allow compiling of the component.
  92. version 1.1 - July 23th 1997
  93.       * Fixed bug: Pieces were not displayed properly when being dragged
  94.         if the Chessboard were not the child of the form.
  95.       * Fixed bug: The letters A-H were not displayed in the right position
  96.         if WhiteOnTop were TRUE.
  97.       * Removed property Align because it was put there without the
  98.         intention.
  99.       * Added property Enabled, which allows to lock the Chessboard
  100.       * Added member function DrawChessPiece which allows displaying
  101.         of a chess piece outside of the component.
  102.       * Datatype Square is now being used consequently
  103.  
  104. version 1.0 - June 20th 1997
  105.       * Added PAS file for Delphi2 and Delphi3
  106. version 1.0 - June 11th 1997
  107.       * initial version (C++ Builder only)
  108. ----------------------------------------------------------------------------
  109. Property Descriptions:
  110.  
  111. bool BoardLines
  112.      Determines whether lines will be drawn
  113.      around the board and between the squares
  114.  
  115. TBitmap BorderBitmap
  116.      If assigned a value, this bitmap will be used to draw the border around
  117.      the board. BorderColor will then be ignored.
  118.  
  119. TColor BorderColor
  120.     Sets the color of the border. Will be visible only if no value has
  121.     been assigned to BorderBitmap.
  122.  
  123. CastleSet CastlingAllowed
  124.      This set stores whether castling is still allowed for each king in each
  125.      for white while CastleSet>>BlackQueenSide will disable long castling
  126.      for Black.
  127.  
  128. bool ComputerPlaysBlack
  129. Lets the computer think and move automatically when it's black's turn.
  130.  
  131. bool ComputerPlaysWhite
  132. Lets the computer think and move automatically when it's white's turn.
  133.  
  134. TFont CoordFont
  135.     Sets the font eventually used to display the coordinates around the board.
  136.  
  137. int CurrentMove (read-only)
  138.      Stores the current move of the game in the list. CurrentMove cannot be
  139.      to change its value.
  140.  
  141. TBitmap CustomPieceSet
  142.      If assigned a legal value (that is a bitmap with a Width of
  143.      1.5 times its Height) this bitmap will be used as the new piece set
  144.      instead of the default The bitmap should consist of 6 x 4 smaller square
  145.      bitmaps of equal size. The order of the pieces should be: pawn, knight,
  146.      bishop, rook, queen and king. The first row represents the white pieces,
  147.      the third row represents the black pieces. The second and fourth row
  148.      should be monochrome and will be used to determine the mask of the white
  149.      and black pieces respectively. The pieces will not be shown in the place
  150.      where the mask bitmap contains a non-zero value. This allows transparent
  151.      drawing of the pieces on the board.
  152.  
  153. CoordSet DisplayCoords
  154.      Determines whether coordinates are being displayed around the screen.
  155.      Examples: DisplayCoords<<West will display coordinates on the left of
  156.      the board. DisplayCoords>>East will make disappear coordinates at the
  157.      right of the board.
  158.  
  159.  
  160. Square EnPassant
  161.      if EnPassant doesn't equal None, it contains the square on which
  162.      an EnPassant capture can take place. If white moves for instance
  163.      E2-E4, EnPassant will be set to the value E3 (on which the pawn
  164.      can be taken).  Legal values are: A3-H3, A6-H6
  165.  
  166. TPen LineStyle
  167.      Contains the linestyle eventually used to display lines between
  168.      the squares and around the board.
  169.  
  170. String Position
  171.      The contents of the board are stored in this string which is
  172.      always 64 characters long. The board is stored from square
  173.      A8 through H8 to H1. Each character represents a piece on the
  174.      board. The characters P, N, B, R, Q, K represent the pawn
  175.      knight, bishop, rook, queen and king respectively.
  176.      White pieces are uppercased, black pieces lowercased. Empty
  177.      squares are represented by spaces.
  178.      To quickly initialize a standard setup, fill the string
  179.      with 'init'.
  180.  
  181. bool Resizable
  182.      Determines whether the ChessBoard can be resized. If TRUE,
  183.      when the user moves the cursor over the right-down corner,
  184.      the shape of the cursor will change and allow the ChessBoard
  185.      to be resized. The resizing does not yet happen flicker-free.
  186.  
  187. int ResizeMinSize
  188.      The minimum allowed size of the ChessBoard (it's Width and Height)
  189.      while it is in the resizing state.
  190.  
  191. int ResizeMaxSize
  192.      The maximum allowed size of the ChessBoard (it's Width and Height)
  193.      while it is in the resizing state.
  194.  
  195. int SearchDepth
  196.      Sets the searchdepth of Tom's chess engine. With each point the
  197.      searchdepth is increased, the time it takes to calculate a move grows
  198.      exponentially.
  199.  
  200. int SizeOfBorder
  201.      Determines the width of the border around the board. Changing its
  202.      value may change the size of the chessboard as well. (Width and Height)
  203.  
  204. int SizeOfSquare
  205.      Determines the squaresize. Changing its value may change the size of
  206.      the chessboard as well. (Width and Height)
  207.  
  208. TColor SquareColorDark
  209.     The color of the dark squares. Will be visible only if no value has
  210.     been assigned to SquareDark.
  211.  
  212. TColor SquareColorLight
  213.     The color of the light squares. Will be visible only if no value has
  214.     been assigned to SquareLight.
  215.  
  216. TBitmap SquareDark
  217.      If assigned a value, this bitmap will be used to draw the border around
  218.      the board to display the dark squares. SquareColorDark will then be
  219.      ignored.
  220.  
  221. TBitmap SquareLight
  222.      If assigned a value, this bitmap will be used to display the light
  223.      squares. SquareColorLight will then be ignored.
  224.  
  225. StandardSet StandardSize
  226.     Sets the size of the standard pieceset. The standard pieceset will
  227.     only be used if no value has been assigned to CustomPieceSet.
  228.     Legal values are: size32, size40, size64 and size80
  229.  
  230. bool Thinking (read-only)
  231. Is set to TRUE if the computer is currently thinking about a move.
  232.  
  233. TThreadPriority ThinkingPriority
  234. Sets the priority of the thinking thread. Cannot be higher than tpNormal so
  235. the stability does not get jeopardized.
  236.  
  237. bool WhiteOnTop
  238.      Controls whether the white pieces are being
  239.      displayed on top of the board. Use: WhiteOnTop=!WhiteOnTop to flip the
  240.      board.
  241.  
  242. bool WhiteToMove
  243.      Readonly. Sets the turn to white if TRUE and to black if FALSE;
  244. --------------------------------------------------------------------------
  245. Methods of the Public Interface:
  246.  
  247. -Pieces can contain the following (char) values:
  248.  p,b,n,r,q or k for a black pawn, knight bishop, rook queen or king
  249.  P,B,N,R,Q or K for a white pawn, knight bishop, rook queen or king
  250.  
  251. bool __fastcall BlackInCheckAfter(Square oldSq, Square newSq)
  252.        returns TRUE if black is in check after the indicated move
  253.  
  254. void __fastcall CancelThinking(void)
  255.        Stops calculating if the computer was thinking about a move.
  256.  
  257. bool __fastcall ClearSquare(int sqn)
  258.        will empty the square with number sqn
  259.  
  260. static int inline __fastcall ColorOfPiece (char piece)
  261.        returns BLACK (0) or WHITE  (1) if piece is a legal piece
  262.        otherwise NOPIECE (-1)
  263.  
  264. static int inline __fastcall ColorOfSquare (Square sqno)
  265. function ColorOfSquare (sq: Square): Integer
  266.        returns BLACK or WHITE according to the color of square sqno.
  267.  
  268. void __fastcall DrawChessPiece(TCanvas *canvas, int x, int y,char piece)
  269. procedure DrawChessPiece (canvas: TCanvas; x,y: Integer; piece: Char)
  270.        Draws the Chess piece, indicated by 'piece'  on the given canvas,
  271.        at the given offset (x,y).
  272.        This method uses some kind of MaskBlt, and draws only in the place
  273.        where the mask has its bits set so drawing on a patterned surface
  274.        is possible.
  275.  
  276. MoveInfo& __fastcall GetMove (int moveno, bool WhiteMoves)
  277.        Returns a MoveInfo structure filled with the information
  278.        about the indicated move. Returns a structure with all
  279.        zero values and an initial position in the case the
  280.        move could not be found in the movelist.
  281.  
  282. TStringList* __fastcall GetMoveList (void)
  283.        Returns a TStringList with all the moves of the current game.
  284.  
  285. bool __fastcall GotoMove (int moveno, bool WhiteMoves)
  286.        Jump to the indicated move in the game and
  287.        set the position accordingly. Returns FALSE if
  288.        the move cannot be found in the movelist.
  289.  
  290. bool __fastcall LegalMoveAvailable (void)
  291.        Returns TRUE if a move can be made from the current position.
  292.  
  293. static Square inline __fastcall MouseToSquare (int x, int y)
  294.        converts coordinates to a square value.
  295.        For instance CoordsToSquare (1,4) will return A4.
  296.  
  297. bool __fastcall Move (Square oldSq, Square newSq)
  298.        will make a move and return TRUE if the move is legal.
  299.        The move will be both displayed on the board and registered in
  300.        memory. For castling: pass the move of the king.
  301.        Example: Move (E2,E4)
  302.  
  303. bool __fastcall MoveBackward (void)
  304.        Moves backward in the list of played moves and sets the position
  305.        accordingly. Returns FALSE if there's no move available.
  306.  
  307. void __fastcall MoveForward (void)
  308.        Moves forward in the list of played moves and sets the position
  309.        accordingly. Returns FALSE if there's no move available.
  310.  
  311. void __fastcall MoveNow (void)
  312.        Starts calculating. The thinkingthread is being set to a state
  313.        in which it produces moves. Function returns before calculation
  314.        has completed.
  315.  
  316. void __fastcall NewGame(void)
  317.        Resets the position to the initial state.
  318.  
  319. bool __fastcall SetUpPosition (MoveInfo &pos, int moveno, bool whitemoves)
  320.        Sets up the ChessBoard according to a given position. The first
  321.        move in the game will be moveno.
  322.  
  323. void __fastcall UpdateChessBoard (String oldpos)
  324.        Ensures all pieces are displayed on the right position.
  325.        Can be used if you change property Position manually.
  326.  
  327. bool __fastcall WhiteInCheckAfter(Square oldsq, Square newsq)
  328.        returns TRUE if white is in check after the indicated move
  329.  
  330. Square  __fastcall WindowToSquare (int x, int y)
  331.        returns the square at the position of (x,y).
  332.        x and y must be relative to the current window.
  333.  
  334. static int inline __fastcall XPos (int sqno)
  335.        returns the x-Coordinate (as an integer number in the range 1-8)
  336.        of the square.
  337.  
  338. static int inline __fastcall YPos (int sqno)
  339.        returns the x-Coordinate (as an integer number in the range 1-8)
  340.        of the square.
  341.  
  342. ---------------------------------------------------------------------------
  343. Event Handlers:
  344.  
  345. The following event handlers can be used.
  346.  
  347. virtual void __fastcall Capture (System::TObject *Sender,
  348.     int oldSq, int newSq, char CapturedPiece)
  349.  
  350. virtual void __fastcall Castle (System::TObject *Sender, Square oldSq,
  351.     Square newSq)
  352.  
  353. virtual void __fastcall Check (System::TObject *Sender,
  354.     Square oldSq, Square newSq)
  355.  
  356. virtual void __fastcall Click(void)
  357.  
  358. virtual void __fastcall DragCanceled(void)
  359.  
  360. virtual void __fastcall DragDrop(System::TObject *Source,int X, int Y)
  361.  
  362. virtual void __fastcall DragOver(System::TObject* Source, int X, int Y,
  363.         TDragState State, bool &Accept )
  364.  
  365. virtual void __fastcall EndDrag(bool drop)
  366.  
  367. virtual void __fastcall IllegalMove (System::TObject *Sender,  Square sq)
  368.  
  369. virtual void __fastcall LegalMove (System::TObject *Sender,
  370.         Square oldSq, Square newSq)
  371.  
  372. virtual void __fastcall Mate (System::TObject *Sender,
  373.         Square oldSq, Square newSq)
  374.  
  375. virtual void __fastcall MouseDown(TMouseButton Button,
  376.     Classes::TShiftState Shift, int X, int Y)
  377.  
  378. virtual void __fastcall MouseMove(Classes::TShiftState Shift, int X, int Y)
  379.  
  380. virtual void __fastcall MouseUp(TMouseButton Button,
  381.     Classes::TShiftState Shift, int X, int Y)
  382.  
  383. virtual void __fastcall OnlyTwoKingsLeft (System::TObject *Sender)
  384.  
  385. virtual void __fastcall Paint(void)
  386.  
  387. virtual void __fastcall Promotion
  388.     (System::TObject *Sender,  Square oldSq, Square newSq, char &NewPiece)
  389.  
  390. virtual void __fastcall StaleMate (System::TObject *Sender,
  391.     Square oldSq, Square newSq)
  392.  
  393. virtual void __fastcall ThreefoldPosition (System::TObject *Sender)
  394.  
  395. ------------------------------------------------------------------------------
  396.  
  397. Copyright, Liability and Author:
  398.  
  399. The Chessboard component may be freely used and distributed by anyone.
  400. The author does not accept liability for the software in any way.
  401.  
  402. Note that the standard pieceset that's being used comes straight out of
  403. Fritz4 for I thought I would never be able to design such clear and charming
  404. pieces. So take care not to break any laws with copyrighted material.
  405. If you would like to receive some Chess pieces from some other popular
  406. Chess programs, just drop me a line, which you can do as well if you
  407. have any bug reports, comments, suggestions, or wanted features:
  408.  
  409. Daniel Terhell
  410. Amsterdam
  411. Tel: +31 20 4866128
  412. kr8m8pr8@compuserve.com
  413. http://ourworld.compuserve.com/homepages/kr8m8pr8
  414. ------------------------------------------------------------------------------
  415.  
  416.